package com.han.transfer.process.impl;

import com.han.transfer.constant.BaseParameter;
import com.han.transfer.process.AbstractGenerator;
import com.han.transfer.util.Painter;
import com.han.transfer.util.TransferUtil;

import java.awt.*;

/**
 * @author HanJiafeng
 * @date 2021/6/8 11:10
 * @desc 每个字符都手动绘制
 */
public class CharacterGeneratorImpl extends AbstractGenerator {
    public CharacterGeneratorImpl() {
        super();
    }

    @Override
    protected void drawHeader(Graphics2D billGraphics2D, String phoneTime, int battery) {

        Image image = Painter.draw(27,
                phoneTime,
                new Color(97, 97, 97),
                new Color(242, 242, 242)
        );
        billGraphics2D.drawImage(image, 1020, 22, null);

        billGraphics2D.setColor(new Color(96, 97, 99));
        int width = (int) (((double) battery / 100d) * 42d);
        billGraphics2D.fillRoundRect(954, 26, width, 21, 5, 5);

        //画上账单详情
        Image detail = Painter.draw(50,
                "账单详情",
                Font.BOLD,
                Color.black,
                new Color(242, 242, 242));
        int amountImageWidth = detail.getWidth(null);
        int amountImageX = (getTemplateImageWidth() - amountImageWidth) / 2;
        billGraphics2D.drawImage(detail, amountImageX, 123, null);

        //画上全部账单
        Image allBill = Painter.draw(50,
                "全部账单",
                Color.BLACK,
                new Color(242, 242, 242));
        billGraphics2D.drawImage(allBill, 925, 123, null);
    }

    @Override
    protected void drawPayee(Graphics2D billGraphics2D, BaseParameter.Payment payment, String payee) {

        String content = payment.toString() + "-给" + payee;
        Image image = Painter.draw(50, content);

        int amountImageWidth = image.getWidth(null);
        int amountImageX = (getTemplateImageWidth() - amountImageWidth) / 2;
        billGraphics2D.drawImage(image, amountImageX, 488, null);
    }

    @Override
    protected void drawPaymentInfo(Graphics2D billGraphics2D, String paymentMode, String transferTime) {
        String[][] paymentInfos = {
                {"当前状态", "支付成功", "40"},
                {"收款方备注", "二维码收款", "40"},
                {"支付方式", paymentMode, "40"},
                {"转账时间", transferTime, "35"},
                {"转账单号", TransferUtil.generateTransferId(transferTime), "35"},
        };
        int y = 903;
        for (String[] paymentInfo : paymentInfos) {
            Image keyImage = Painter.draw(
                    40,
                    paymentInfo[0],
                    new Color(136, 136, 136)
            );
            billGraphics2D.drawImage(keyImage, 92, y, null);
            Image valueImage = Painter.draw(
                    Integer.parseInt(paymentInfo[2]),
                    paymentInfo[1],
                    new Color(53, 53, 53)
            );
            billGraphics2D.drawImage(valueImage, 366, y, null);
            y += 90;
        }
    }

    @Override
    protected void drawTail(Graphics2D billGraphics2D) {
        String[] tails = {"发起群收款", "联系收款方", "对订单有疑惑", "常见问题"};
        int y = 1506;
        for (String tail : tails) {
            Image tailImage = Painter.draw(40,
                    tail,
                    new Color(52, 52, 52));
            billGraphics2D.drawImage(tailImage, 92, y, null);
            y += 177;
        }
    }
}
